//
//  HDResourceCollectionView.m
//  HDLiaoNing
//
//  Created by 牛的mini on 1/7/15.
//  Copyright (c) 2015 牛的mini. All rights reserved.
//

#import "HDResourceCollectionView.h"
#import "HDResourceCollectionViewCell.h"
#import "HD_HSP_Exhibit_Model.h"

static HDDeclare *declare;
@implementation HDResourceCollectionView

- (void)awakeFromNib
{
    self.dataSource = self;
    self.delegate = self;
    declare = [HDDeclare sharedDeclare];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"resourceCell";
    HDResourceCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
    UIImage *cellImage;
    if (cellImage == nil)
    {
        cellImage = [UIImage imageNamed:@"relics_default"];
    }
    cell.imageView.image = cellImage;
    

    HD_HSP_Exhibit_Model *model = self.dataArray[indexPath.row];
    cell.textLabel.text = model.FileName;
    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{
    CGFloat width = self.frame.size.width/3-10;
    return CGSizeMake(width, width/11*7+5);

//    return CGSizeMake(width, width-25);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
//    cell.backgroundColor = [UIColor whiteColor];
    
    self.myTapBlock(indexPath.row);
    
    [self deselectItemAtIndexPath:indexPath animated:YES];
}


- (void)dealloc
{
    self.myTapBlock = nil;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
